home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dosrcss.zip / RLOG.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  41KB  |  1,268 lines

  1. /*
  2.  *                       RLOG    operation
  3.  */
  4. #ifndef lint
  5. static char rcsid[]=
  6. "$Header: /site/tmp/dosrcs/src/RCS/rlog.c,v 5.4 90/07/15 22:55:38 lfk Release $ Purdue CS";
  7. #endif
  8. /*****************************************************************************
  9.  *                       print contents of RCS files
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40.  
  41. /* $Log:    rlog.c,v $
  42.  * Revision 5.4  90/07/15  22:55:38  lfk
  43.  * Almost the end of major revison for MS-DOS version of RCS
  44.  * 
  45.  * Revision 5.3  90/07/15  20:26:14  lfk
  46.  * Most major fixes added between rev 5.1 and rev 5.5:
  47.  *     signals fixed so they work on MS-DOS
  48.  *     Added MKS arguments code so argv can be large
  49.  *     added code to handle slashes a'la Unix
  50.  *     added more file extensions to system from MS-DOS
  51.  * 
  52.  * Revision 5.2  90/07/15  11:35:39  ROOT_DOS
  53.  * DOS version of RCS 4.0 checked in for MODS
  54.  * by lfk@athena.mit.edu
  55.  * Also update to MSC 6.0
  56.  * 
  57.  * Revision 4.7  89/05/01  15:13:48  narten
  58.  * changed copyright header to reflect current distribution rules
  59.  * 
  60.  * Revision 4.6  88/11/08  11:59:40  narten
  61.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  62.  * 
  63.  * Revision 4.6  88/08/09  19:13:28  eggert
  64.  * Check for memory exhaustion; don't access freed storage.
  65.  * Shrink stdio code size; remove lint.
  66.  * 
  67.  * Revision 4.5  87/12/18  11:46:38  narten
  68.  * more lint cleanups (Guy Harris)
  69.  * 
  70.  * Revision 4.4  87/10/18  10:41:12  narten
  71.  * Updating version numbers
  72.  * Changes relative to 1.1 actually relative to 4.2
  73.  * 
  74.  * Revision 1.3  87/09/24  14:01:10  narten
  75.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  76.  * warnings)
  77.  * 
  78.  * Revision 1.2  87/03/27  14:22:45  jenkins
  79.  * Port to suns
  80.  * 
  81.  * Revision 1.1  84/01/23  14:50:45  kcs
  82.  * Initial revision
  83.  * 
  84.  * Revision 4.2  83/12/05  09:18:09  wft
  85.  * changed rewriteflag to external.
  86.  * 
  87.  * Revision 4.1  83/05/11  16:16:55  wft
  88.  * Added -b, updated getnumericrev() accordingly.
  89.  * Replaced getpwuid() with getcaller().
  90.  * 
  91.  * Revision 3.7  83/05/11  14:24:13  wft
  92.  * Added options -L and -R;
  93.  * Fixed selection bug with -l on multiple files.
  94.  * Fixed error on dates of the form -d'>date' (rewrote getdatepair()).
  95.  * 
  96.  * Revision 3.6  82/12/24  15:57:53  wft
  97.  * shortened output format.
  98.  *
  99.  * Revision 3.5  82/12/08  21:45:26  wft
  100.  * removed call to checkaccesslist(); used DATEFORM to format all dates;
  101.  * removed unused variables.
  102.  *
  103.  * Revision 3.4  82/12/04  13:26:25  wft
  104.  * Replaced getdelta() with gettree(); removed updating of field lockedby.
  105.  *
  106.  * Revision 3.3  82/12/03  14:08:20  wft
  107.  * Replaced getlogin with getpwuid(), %02d with %.2d, fancydate with PRINTDATE.
  108.  * Fixed printing of nil, removed printing of Suffix,
  109.  * added shortcut if no revisions are printed, disambiguated struct members.
  110.  *
  111.  * Revision 3.2  82/10/18  21:09:06  wft
  112.  * call to curdir replaced with getfullRCSname(),
  113.  * fixed call to getlogin(), cosmetic changes on output,
  114.  * changed conflicting long identifiers.
  115.  *
  116.  * Revision 3.1  82/10/13  16:07:56  wft
  117.  * fixed type of variables receiving from getc() (char -> int).
  118.  */
  119.  
  120.  
  121.  
  122. #include "time.h"
  123. #include "rcsbase.h"
  124. #ifndef lint
  125. static char rcsbaseid[] = RCSBASE;
  126. #endif
  127.  
  128. extern char * partialno();
  129. extern char * getcaller();          /*get login of caller                   */
  130. extern        free();
  131. extern int    countnumflds();
  132. extern int    compartial();
  133. extern int    expandsym();          /*get numeric name of a revision        */
  134. extern int nextc;                   /*next input character                  */
  135. extern char Klog[];
  136. extern char Ktext[];
  137. extern int  partime();
  138. extern long maketime();             /*convert parsed time to unix time.     */
  139. extern struct tm * localtime();     /*convert unixtime into a tm-structure  */
  140. extern int  pairfilenames();
  141. extern struct hshentry  * getnum();
  142. extern FILE * finptr;               /* RCS input file                       */
  143. extern FILE * frewrite;             /* new RCS file                         */
  144. extern int    rewriteflag;          /* indicates whether input should be    */
  145.                     /* echoed to frewrite */
  146. extern int    nerror;               /* error counter                        */
  147.  
  148. char * RCSfilename, * workfilename;
  149.  
  150. char * caller;                        /* caller's login;                    */
  151. int  descflag, selectflag, selectop;  /* option to print access list, symbolic  */
  152.                                       /* names, descriptive text, locks and */
  153.                                       /* Head                               */
  154. int  onlylockflag;              /* option to print only files         */
  155.                       /* with locks                */
  156. int  onlyRCSflag;                     /* option to print only RCS file name */
  157. int  lockflag;                        /* whether locker option is set       */
  158. int  revno;                           /* number of revision chosen          */
  159.  
  160. struct  lockers {                     /* lockers in locker option; stored   */
  161.      char               * login;      /* lockerlist                         */
  162.      struct     lockers * lockerlink;
  163.      }  ;
  164.  
  165. struct  stateattri {                  /* states in state option; stored in  */
  166.      char               * status;     /* statelist                          */
  167.      struct  stateattri * nextstate;
  168.      }  ;
  169.  
  170. struct  authors {                     /* login names in author option;      */
  171.      char               * login;      /* stored in authorlist               */
  172.      struct     authors * nextauthor;
  173.      }  ;
  174.  
  175. struct Revpairs{                      /* revision or branch range in -r     */
  176.      int                  numfld;     /* option; stored in revlist          */
  177.      char               * strtrev;
  178.      char               * endrev;
  179.      struct  Revpairs   * rnext;
  180.      } ;
  181.  
  182. struct Datepairs{                     /* date range in -d option; stored in */
  183.      char               strtdate[datelength];   /* duelst and datelist      */
  184.      char               enddate[datelength];
  185.      struct  Datepairs  * dnext;
  186.      };
  187.  
  188. char   Dotstring[200];                /* string of numeric revision name    */
  189. char   * Nextdotstring;               /* next available place of Dotstring  */
  190. struct  Datepairs       * datelist,  * duelst;
  191. struct  Revpairs        * revlist, * Revlst;
  192. int                     branchflag; /* set on -b */
  193. struct  lockers         * lockerlist;
  194. struct  stateattri      * statelist;
  195. struct  authors         * authorlist;
  196.  
  197.  
  198.  
  199. #ifdef MKS
  200. main( int argc, char * argv[], char * env[] )
  201. #else
  202. main( argc, argv )
  203. int argc;
  204. char *argv[];
  205. #endif /* MKS Startup Args */
  206. {
  207.         struct  Datepairs       * currdate;
  208.         struct  assoc         * curassoc;
  209.         struct  access        * curaccess;
  210.         struct  lock          * currlock;
  211.         char * cmdusage;
  212.  
  213. #ifdef MKS /* MKS Startup stuff */
  214.     int z = 0;
  215.     int ARGC = 0;
  216.     char **tmp;
  217.     char *env_name;
  218. #    define MAXARGS 100        /* This means 500 items on the command line */
  219.     if (!(tmp = (char **)malloc(sizeof(char *)*(MAXARGS+1)))) {
  220.         fprintf(stderr, "%s: can't allocate space for arguments\n",argv[0]);
  221.         exit(1);
  222.     }
  223.     for ( z = 0 ; env[z] != NULL; z++) {    /* loop through environment */
  224.         if (*env[z] == '~') {    /* testing for entries begining with '~' */
  225.             *++env[z];            /* increment pointer to delete '~' */
  226.             tmp[ARGC++] = env[z];    /* add it to our new array */
  227.             if (z >= MAXARGS) {
  228.                 fprintf(stderr, "%s: can't handle any more arguments\n", argv[0]);
  229.                 goto list;
  230.             }
  231.         }
  232.         else if (*env[z] == '_') {    /* testing for entries begining with _ */
  233.             *++env[z] ; *++env[z];    /* move past the '_' and the '=' */
  234.             env_name = env[z];    /* copy the name */
  235.         }
  236.     }
  237. list:
  238.     if ( STREQ( (char *) argv[0] , env_name ) ) {    /* test name against startup args */
  239.         /* environment arguments meant for this program */
  240. #    ifdef DEBUG
  241.         printf("Using shell supplied args\n");
  242. #    endif
  243.         argc = ARGC;
  244.         tmp[ARGC] = NULL;    /* the terminal NULL */
  245.         argv = tmp;
  246.     }
  247. #    ifdef DEBUG
  248.     else 
  249.         printf("Using startup supplied args\n");
  250. #    endif /* debug */
  251. #endif /* MKS */
  252.     cmdusage = "command format:\nrlog -L -R -h -t -b -ddates -l[lockers] -rrevisions -sstates -w[logins] file ...";
  253.         cmdid = "rlog";
  254.         descflag = selectflag = true;
  255.         lockflag = onlylockflag = selectop = false;
  256.     onlyRCSflag = false;
  257.         lockerlist = nil;
  258.         authorlist = nil;
  259.         statelist = nil;
  260.         Revlst = revlist = nil;
  261.         branchflag= false;
  262.         duelst = datelist = nil;
  263.     caller=getcaller();
  264.  
  265.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  266.                 switch ((*argv)[1]) {
  267.  
  268.         case 'L':
  269.             onlylockflag = true;
  270.             break;
  271.  
  272.         case 'R':
  273.             onlyRCSflag =true;
  274.             break;
  275.  
  276.                 case 'l':
  277.                         selectop = true;
  278.                         lockflag = true;
  279.                         getlocker( (*argv)+2 );
  280.                         break;
  281.  
  282.                 case 'b':
  283.                         selectop = true;
  284.                         branchflag = true;
  285.                         break;
  286.  
  287.                 case 'r':
  288.                         selectop = true;
  289.                         getrevpairs( (*argv)+2 );
  290.                         break;
  291.  
  292.                 case 'd':
  293.                         selectop = true;
  294.                         getdatepair( (*argv)+2 );
  295.                         break;
  296.  
  297.                 case 's':
  298.                         selectop = true;
  299.                         getstate( (*argv)+2);
  300.                         break;
  301.  
  302.                 case 'w':
  303.                         selectop = true;
  304.                         getauthor( (*argv)+2);
  305.                         break;
  306.  
  307.                 case 'h':
  308.                         if ( ! selectflag ) warn("option -t overrides -h");
  309.                         else    descflag = false;
  310.                         break;
  311.  
  312.                 case 't':
  313.                         selectflag = false;
  314.                         if ( ! descflag ) warn("option -t overrides -h");
  315.                         descflag = true;
  316.                         break;
  317.  
  318.                 default:
  319.                         faterror("unknown option: %s\n%s", *argv,cmdusage);
  320.  
  321.                 };
  322.         } /* end of option processing */
  323.  
  324.         if (argc<1) faterror("No input file\n%s",cmdusage);
  325.  
  326.  
  327.         /* now handle all filenames */
  328.         do {
  329.             rewriteflag=false;
  330.             finptr=frewrite=nil;
  331.  
  332.  
  333.             if (!pairfilenames(argc, argv, true,false)) continue;
  334.  
  335.             /* now RCSfilename contains the name of the RCS file, and finptr
  336.              * the file descriptor. Workfilename contains the name of the
  337.              * working file.
  338.              */
  339.  
  340.             if ( !trysema(RCSfilename, false)) goto loopend; /*  give up */
  341.  
  342.             /* do nothing if -L is given and there are no locks*/
  343.         if ( onlylockflag && Locks == nil ) goto loopend;
  344.  
  345.         if ( onlyRCSflag ) {
  346.         VOID fprintf(stdout, "%s\n", RCSfilename);
  347.         goto loopend;
  348.         }
  349.             /*   print RCS filename , working filename and optional
  350.                  administrative information                         */
  351.             VOID fprintf(stdout, "\nRCS file:        %s;   ",RCSfilename);
  352.             /* could use getfullRCSname() here, but that is very slow */
  353.             VOID fprintf(stdout, "Working file:    %s\n", workfilename);
  354.             VOID fprintf(stdout, "head:            %s\n", Head==nil?"":Head->num);
  355.             VOID fprintf(stdout, "branch:          %s\n", Dbranch==nil?"":Dbranch->num);
  356.  
  357.             VOID fputs("locks:         ", stdout);  /*  print locker list   */
  358.             currlock = Locks;
  359.             while( currlock ) {
  360.                 VOID fprintf(stdout,"  %s: %s;", currlock->login,
  361.                                 currlock->delta->num);
  362.                 currlock = currlock->nextlock;
  363.             }
  364.             if ( StrictLocks )
  365.                 VOID fputs(Locks==nil?"  ;  strict":"  strict",stdout);
  366.  
  367.             VOID fputs("\naccess list:   ", stdout);      /*  print access list  */
  368.             curaccess = AccessList;
  369.             while(curaccess) {
  370.                 VOID fputs("  ",stdout);
  371.                 VOID fputs(curaccess->login, stdout);
  372.                 curaccess = curaccess->nextaccess;
  373.             }
  374.  
  375.             VOID fputs("\nsymbolic names:", stdout);   /*  print symbolic names   */
  376.             curassoc = Symbols;
  377.             while( curassoc ) {
  378.                 VOID fprintf(stdout, "  %s: %s;",curassoc->symbol,
  379.                            curassoc->delta->num);
  380.                 curassoc = curassoc->nextassoc;
  381.             }
  382.  
  383.             VOID fprintf(stdout,"\ncomment leader:  \"%s\"\n",Comment);
  384.  
  385.             gettree();
  386.             VOID fprintf(stdout, "total revisions: %d;    ", TotalDeltas);
  387.             if ( Head == nil || !selectflag || !descflag) {
  388.                 VOID putc('\n',stdout);
  389.                 if (descflag) VOID fputs("description:\n", stdout);
  390.                 getdesc(descflag);
  391.                 VOID fputs("=============================================================================\n",stdout);
  392.                 goto loopend;
  393.             }
  394.  
  395.  
  396.             /*  keep only those locks given by -l */
  397.             if (lockflag)
  398.                 trunclocks();
  399.             getnumericrev();    /* get numeric revision or branch names */
  400.             revno = 0;
  401.  
  402.             exttree(Head);
  403.  
  404.             /*  get most recently date of the dates pointed by duelst  */
  405.             currdate = duelst;
  406.             while( currdate) {
  407.                 recentdate(Head, currdate);
  408.                 currdate = currdate->dnext;
  409.         }
  410.  
  411.             extdate(Head);
  412.  
  413.             /*  reinitialize the date specification list   */
  414.             currdate = duelst;
  415.             while(currdate) {
  416.                 VOID sprintf(currdate->strtdate,DATEFORM,0,0,0,0,0,0);
  417.                 currdate = currdate->dnext;
  418.             }
  419.  
  420.             if ( selectop || ( selectflag && descflag) )
  421.                 VOID fprintf(stdout, "selected revisions: %d", revno);
  422.             VOID putc('\n', stdout);
  423.             if (descflag) VOID fputs("description:\n", stdout);
  424.             getdesc(descflag);
  425.             while( (nexttok != EOFILE) && readdeltalog());
  426.             if (selectflag && descflag && revno) {
  427.                 putrunk();
  428.                 putree(Head);
  429.                 if (nextlex(), nexttok != EOFILE)
  430.                     fatserror("syntax error; expecting EOF");
  431.             }
  432.             VOID fputs("=============================================================================\n",stdout);
  433.         loopend:
  434.             VOID fclose(finptr);
  435.         } while( ++argv, --argc >= 1);
  436.         exit(nerror!=0);
  437. }
  438.  
  439.  
  440.  
  441. putrunk()
  442. /*  function:  print revisions chosen, which are in trunk      */
  443.  
  444. {
  445.         struct  hshentry        * ptr, * pre;
  446.  
  447.         if (Head == nil) return;   /*  empty tree  */
  448.  
  449.         pre = Head;
  450.         ptr = Head->next;
  451.         while( ptr ) {
  452.             putadelta(pre,ptr,true);
  453.             pre = ptr;
  454.             ptr = ptr->next;
  455.         }
  456.         putadelta(pre,ptr,true);
  457. }
  458.  
  459.  
  460.  
  461. putree(root)
  462. struct  hshentry  *root;
  463. /*   function: print delta tree( not include trunck) in reversed calender
  464.                order on each branch                                        */
  465.  
  466. {
  467.         if ( root == nil ) return;
  468.  
  469.         putree(root->next);
  470.  
  471.         putforest(root->branches);
  472. }
  473.  
  474.  
  475.  
  476.  
  477. putforest(branchroot)
  478. struct   branchhead     * branchroot;
  479. /*   function:  print branches that has the same direct ancestor    */
  480. {
  481.  
  482.         if ( branchroot == nil ) return;
  483.  
  484.         putforest(branchroot->nextbranch);
  485.  
  486.         putabranch(branchroot->hsh);
  487.         putree(branchroot->hsh);
  488. }
  489.  
  490.  
  491.  
  492.  
  493. putabranch(root)
  494. struct      hshentry   *root;
  495. /*   function  :  print one branch     */
  496.  
  497. {
  498.  
  499.         if ( root == nil) return;
  500.  
  501.         putabranch(root->next);
  502.  
  503.         putadelta(root, root, false);
  504. }
  505.  
  506.  
  507.  
  508.  
  509.  
  510. putadelta(node,editscript,trunk)
  511. register  struct   hshentry    * node;
  512. register  struct   hshentry    * editscript;
  513. int                              trunk;
  514. /*  function: print delta node if node->selector is 's'.        */
  515. /*      editscript indicates where the editscript is stored     */
  516. /*      trunk indicated whether this node is in trunk           */
  517. {
  518.         struct  branchhead      * newbranch;
  519.         char                    * branchnum,  branch[40];
  520.  
  521.         if ( ( node == nil) || ( node->selector == 'u'))
  522.             return;
  523.  
  524.         VOID fprintf(stdout,"----------------------------\n");
  525.         VOID fprintf(stdout, "revision %s        ",node->num);
  526.         if ( node->lockedby )
  527.            VOID fprintf(stdout, "locked by: %s;       ", node->lockedby);
  528.         VOID putc('\n', stdout);
  529.  
  530.         VOID fputs("date: ",stdout);
  531.         VOID PRINTDATE(stdout,node->date); VOID putc(' ',stdout);
  532.         VOID PRINTTIME(stdout,node->date);
  533.         VOID fprintf(stdout, ";  author: %s;  ", node->author);
  534.         VOID fprintf(stdout, "state: %s;  ", node->state);
  535.  
  536.         if ( editscript )
  537.            if(trunk)
  538.               VOID fprintf(stdout,"lines added/del: %d/%d",
  539.                              editscript->deletelns, editscript->insertlns);
  540.            else
  541.               VOID fprintf(stdout,"lines added/del: %d/%d",
  542.                              editscript->insertlns, editscript->deletelns);
  543.  
  544.         VOID putc('\n', stdout);
  545.  
  546.         branchnum = & (branch[0]);
  547.         newbranch = node->branches;
  548.         if ( newbranch ) {
  549.            VOID fputs("branches:  ", stdout);
  550.            while( newbranch ) {
  551.                 getbranchno(newbranch->hsh->num, branchnum);
  552.                 VOID fprintf(stdout, "%s;  ", branchnum);
  553.                 newbranch = newbranch->nextbranch;
  554.            }
  555.            VOID putc('\n', stdout);
  556.         }
  557.  
  558.         VOID fputs(node->log,stdout);
  559. }
  560.  
  561.  
  562.  
  563.  
  564.  
  565. readdeltalog()
  566. /*  Function : get the log message and skip the text of a deltatext node.
  567.  *             Return false if current block does not start with a number.
  568.  *             Assumes the current lexeme is not yet in nexttok; does not
  569.  *             advance nexttok.
  570.  */
  571. {
  572.         register struct  hshentry  * Delta;
  573.  
  574.         nextlex();
  575.         if ( !(Delta = getnum() )) return(false);
  576.         if ( ! getkey(Klog) || ( nexttok != STRING ) )
  577.                 fatserror("Missing log entry");
  578.         Delta->log = talloc(logsize);
  579.         VOID savestring(Delta->log, logsize);
  580.         nextlex();
  581.         if ( ! getkey(Ktext) || (nexttok != STRING) )
  582.                 fatserror("Missing delta text");
  583.         Delta->insertlns = Delta->deletelns = 0;
  584.         if ( Delta != Head)
  585.                 getscript(Delta);
  586.         else
  587.                 readstring();
  588.         return true;
  589. }
  590.  
  591.  
  592.  
  593. getscript(Delta)
  594. struct    hshentry   * Delta;
  595. /*   function:  read edit script of Delta and count how many lines added  */
  596. /*              and deleted in the script                                 */
  597.  
  598. {
  599.         int ed;   /*  editor command  */
  600.     register FILE * fin;
  601.         register  int   c;
  602.         register  int   i;
  603.         int             length;
  604.  
  605.     fin = finptr;
  606.     while( (ed = getc(fin)) != EOF) {
  607.            /*  assume first none white character is command name  */
  608.             while( ed == '\n' || ed == ' ' || ed == '\t')
  609.         ed = getc(fin);
  610.             if (ed == SDELIM) break;  /*  script text is ended   */
  611.         while( ( c = getc(fin)) == ' ' );  /*  skip blank  */
  612.             if ( ! ('0' <= c && c <= '9')) {
  613.                 faterror("Missing line number in edit script");
  614.                 break;
  615.             }
  616.         while( '0' <= (c = getc(fin)) && c <= '9' ) ;
  617.  
  618.         while( c == ' ')c = getc(fin);  /*  skip blanks  */
  619.             if ( !('0' <= c && c <= '9' ) ) {
  620.                 faterror("Incorrect range in edit script");
  621.                 break;
  622.             }
  623.             length = c - '0';
  624.         while( '0' <= (c = getc(fin)) && c <= '9' )
  625.                 length = length * 10 + c - '0';
  626.         while( c != '\n' && c != EOF) c = getc(fin);
  627.             switch (ed) {
  628.             case 'd' :
  629.                  Delta->deletelns += length;
  630.                  break;
  631.  
  632.             case 'a' :
  633.                  /*  skip scripted lines  */
  634.                  for ( i=length; i > 0 && c != EOF; i--){
  635.              while( (c=getc(fin)) != '\n' && c != EOF);
  636.                      Delta->insertlns++;
  637.                  }
  638.                  break;
  639.  
  640.             default:
  641.                  faterror("Unknown command in edit script: %c", ed);
  642.                  break;
  643.             }
  644.         }
  645.     nextc = getc(fin);
  646. }
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654. exttree(root)
  655. struct hshentry  *root;
  656. /*  function: select revisions , starting with root             */
  657.  
  658. {
  659.         struct branchhead       * newbranch;
  660.  
  661.         if (root == nil) return;
  662.  
  663.         extractdelta(root);
  664.         exttree(root->next);
  665.  
  666.         newbranch = root->branches;
  667.         while( newbranch ) {
  668.             exttree(newbranch->hsh);
  669.             newbranch = newbranch->nextbranch;
  670.         }
  671. }
  672.  
  673.  
  674.  
  675.  
  676. getlocker(argv)
  677. char    * argv;
  678. /*   function : get the login names of lockers from command line   */
  679. /*              and store in lockerlist.                           */
  680.  
  681. {
  682.         register char c;
  683.         struct   lockers   * newlocker;
  684.         argv--;
  685.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  686.                  c == '\n' || c == ';')  ;
  687.         if (  c == '\0') {
  688.             lockerlist=nil;
  689.             return;
  690.         }
  691.  
  692.         while( c != '\0' ) {
  693.             newlocker = ( struct lockers *)talloc( sizeof(struct lockers) );
  694.             newlocker->lockerlink = lockerlist;
  695.             newlocker->login = argv;
  696.             lockerlist = newlocker;
  697.             while ( ( c = (*++argv)) != ',' && c != '\0' && c != ' '
  698.                        && c != '\t' && c != '\n' && c != ';') ;
  699.             *argv = '\0';
  700.             if ( c == '\0' ) return;
  701.             while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  702.                      c == '\n' || c == ';')  ;
  703.         }
  704. }
  705.  
  706.  
  707.  
  708. getauthor(argv)
  709. char   *argv;
  710. /*   function:  get the author's name form command line   */
  711. /*              and store in aauthorlist                  */
  712.  
  713. {
  714.         register    c;
  715.         struct     authors  * newauthor;
  716.  
  717.         argv--;
  718.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  719.                  c == '\n' || c == ';')  ;
  720.         if ( c == '\0' ) {
  721.             authorlist = (struct authors *)talloc(sizeof(struct authors));
  722.             authorlist->login = caller;
  723.             authorlist->nextauthor  = nil;
  724.             return;
  725.         }
  726.  
  727.         while( c != '\0' ) {
  728.             newauthor = (struct authors *)talloc(sizeof(struct authors));
  729.             newauthor->nextauthor = authorlist;
  730.             newauthor->login = argv;
  731.             authorlist = newauthor;
  732.             while( ( c = *++argv) != ',' && c != '\0' && c != ' '
  733.                      && c != '\t' && c != '\n' && c != ';') ;
  734.             * argv = '\0';
  735.             if ( c == '\0') return;
  736.             while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  737.                      c == '\n' || c == ';')  ;
  738.         }
  739. }
  740.  
  741.  
  742.  
  743.  
  744. getstate(argv)
  745. char   * argv;
  746. /*   function :  get the states of revisions from command line  */
  747. /*               and store in statelist                         */
  748.  
  749. {
  750.         register  char  c;
  751.         struct    stateattri    *newstate;
  752.  
  753.         argv--;
  754.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  755.                  c == '\n' || c == ';')  ;
  756.         if ( c == '\0'){
  757.             warn(" Missing state attributes after -s options");
  758.             return;
  759.         }
  760.  
  761.         while( c != '\0' ) {
  762.             newstate = (struct stateattri *)talloc(sizeof(struct stateattri));
  763.             newstate->nextstate = statelist;
  764.             newstate->status = argv;
  765.             statelist = newstate;
  766.             while( (c = (*++argv)) != ',' && c != '\0' && c != ' '
  767.                     && c != '\t' && c != '\n' && c != ';')  ;
  768.             *argv = '\0';
  769.             if ( c == '\0' ) return;
  770.             while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  771.                      c == '\n' || c == ';')  ;
  772.         }
  773. }
  774.  
  775.  
  776.  
  777. trunclocks()
  778. /*  Function:  Truncate the list of locks to those that are held by the  */
  779. /*             id's on lockerlist. Do not truncate if lockerlist empty.  */
  780.  
  781. {
  782.         struct lockers  * plocker;
  783.         struct lock     * plocked,  * nextlocked;
  784.  
  785.         if ( (lockerlist == nil) || (Locks == nil)) return;
  786.  
  787.         /* shorten Locks to those contained in lockerlist */
  788.         plocked = Locks;
  789.         Locks = nil;
  790.         while( plocked != nil) {
  791.             plocker = lockerlist;
  792.             while((plocker != nil) && ( strcmp(plocker->login, plocked->login)!=0))
  793.                 plocker = plocker->lockerlink;
  794.             nextlocked = plocked->nextlock;
  795.             if ( plocker != nil) {
  796.                 plocked->nextlock = Locks;
  797.                 Locks = plocked;
  798.             }
  799.             plocked = nextlocked;
  800.         }
  801. }
  802.  
  803.  
  804.  
  805. recentdate(root, pd)
  806. struct     hshentry    * root;
  807. struct    Datepairs    * pd;
  808. /*  function:  Finds the delta that is closest to the cutoff date given by   */
  809. /*             pd among the revisions selected by exttree.                   */
  810. /*             Successively narrows down the interfal given by pd,           */
  811. /*             and sets the strtdate of pd to the date of the selected delta */
  812. {
  813.         struct  branchhead      * newbranch;
  814.  
  815.     if ( root == nil) return;
  816.         if ( root->selector == 's') {
  817.              if ( cmpnum(root->date, pd->strtdate) >= 0 &&
  818.                   cmpnum(root->date, pd->enddate) <= 0)
  819.         VOID strcpy(pd->strtdate, root->date);
  820.         }
  821.  
  822.         recentdate(root->next, pd);
  823.         newbranch = root->branches;
  824.         while( newbranch) {
  825.            recentdate(newbranch->hsh, pd);
  826.            newbranch = newbranch->nextbranch;
  827.     }
  828. }
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835. extdate(root)
  836. struct  hshentry        * root;
  837. /*  function:  select revisions which are in the date range specified     */
  838. /*             in duelst  and datelist, start at root                     */
  839.  
  840. {
  841.         struct  branchhead      * newbranch;
  842.         struct  Datepairs       * pdate;
  843.  
  844.         if ( root == nil) return;
  845.  
  846.         if ( datelist || duelst) {
  847.             pdate = datelist;
  848.             while( pdate ) {
  849.                 if ( (pdate->strtdate)[0] == '\0' || cmpnum(root->date,pdate->strtdate) >= 0){
  850.                    if ((pdate->enddate)[0] == '\0' || cmpnum(pdate->enddate,root->date) >= 0)
  851.                         break;
  852.                 }
  853.                 pdate = pdate->dnext;
  854.             }
  855.             if ( pdate == nil) {
  856.                 pdate = duelst;
  857.                 while(pdate) {
  858.                    if ( cmpnum(root->date, pdate->strtdate) == 0)
  859.                       break;
  860.                    pdate = pdate->dnext;
  861.                 }
  862.             }
  863.             if ( pdate == nil)
  864.                 root->selector = 'u';
  865.         }
  866.         if (root->selector == 's') revno++;
  867.  
  868.         extdate(root->next);
  869.  
  870.         newbranch = root->branches;
  871.         while( newbranch ) {
  872.            extdate(newbranch->hsh);
  873.            newbranch = newbranch->nextbranch;
  874.         }
  875. }
  876.  
  877.  
  878.  
  879. extractdelta(pdelta)
  880. struct  hshentry        * pdelta;
  881. /*  function:  compare information of pdelta to the authorlst, lockerlist, */
  882. /*             statelist, revlist and mark 's' on selector if pdelta is    */
  883. /*             selected; otherwise, mark 'u'                               */
  884.  
  885. {
  886.         struct  lock            * plock;
  887.         struct  stateattri      * pstate;
  888.         struct  authors         * pauthor;
  889.         struct  Revpairs        * prevision;
  890.         int                       length;
  891.  
  892.         pdelta->selector = 's';
  893.         if ( authorlist ) {  /*  certain author's revisions wanted only  */
  894.             pauthor = authorlist;
  895.             while((pauthor != nil) && ( strcmp(pauthor->login, pdelta->author)!=0))
  896.                 pauthor = pauthor->nextauthor;
  897.             if ( pauthor == nil ) {
  898.                 pdelta->selector = 'u';
  899.                 return;
  900.             }
  901.         }
  902.         if ( statelist ) {   /* revisions with certain state wanted  */
  903.             pstate = statelist;
  904.             while((pstate != nil) && (strcmp(pstate->status, pdelta->state)!=0))
  905.                 pstate = pstate->nextstate;
  906.             if ( pstate == nil ) {
  907.                 pdelta->selector = 'u';
  908.                 return;
  909.             }
  910.         }
  911.         if ( lockflag ) {    /*  locked revisions   */
  912.             plock = Locks;
  913.             while( plock && (plock->delta != pdelta))
  914.                 plock = plock->nextlock;
  915.             if (plock == nil ) {
  916.                 pdelta->selector = 'u';
  917.                 return;
  918.             }
  919.         }
  920.         if ( Revlst ) {   /*  revisions or branches selected  */
  921.  
  922.             prevision = Revlst;
  923.             while( prevision != nil ) {
  924.                 length = prevision->numfld;
  925.                 if ( length % 2 == 1) { /*  a branch number  */
  926.                      if ( countnumflds(pdelta->num) ==(length+1))
  927.                         if ( (compartial(pdelta->num, prevision->strtrev,length) >= 0)&&
  928.                              (compartial(prevision->endrev, pdelta->num, length) >= 0) )
  929.                              break;
  930.                 }
  931.                 else if ( countnumflds(pdelta->num ) == length)  /*  a revision */
  932.                     if ( (compartial(pdelta->num, prevision->strtrev, length) >= 0) &&
  933.                          (compartial(prevision->endrev, pdelta->num, length) >= 0) )
  934.                         break;
  935.                 prevision = prevision->rnext;
  936.             }
  937.             if (prevision == nil)  {
  938.                 pdelta->selector = 'u';
  939.                 return;
  940.             }
  941.         }
  942. }
  943.  
  944.  
  945.  
  946. char * procdate(target, source)
  947. char * target, * source;
  948. /* Function: Parses a free-format date in target, converts it
  949.  * into RCS internal format, and stores the result into source.
  950.  * Returns target on success, nil otherwise.
  951.  */
  952. {
  953.     long            unixtime;
  954.     struct     tm   parseddate,  *ftm;
  955.  
  956.     if ( partime(source, &parseddate) == 0) {
  957.         error("Can't parse date/time: %s", source);
  958.         *target= '\0';
  959.         return nil;
  960.     }
  961.     if ( (unixtime = maketime(&parseddate)) == 0L) {
  962.         error("Inconsistent date/time: %s", source);
  963.         *target='\0';
  964.         return nil;
  965.     }
  966.     ftm = localtime(&unixtime);
  967.     VOID sprintf(target,DATEFORM,
  968.     ftm->tm_year,ftm->tm_mon+1,ftm->tm_mday,ftm->tm_hour,ftm->tm_min,ftm->tm_sec);
  969.     return target;
  970. }
  971.  
  972.  
  973.  
  974. getdatepair(argv)
  975.    char   * argv;
  976. /*  function:  get time range from command line and store in datelist if    */
  977. /*             a time range specified or in duelst if a time spot specified */
  978.  
  979. {
  980.         register   char         c;
  981.         struct     Datepairs    * nextdate;
  982.         char                    * rawdate;
  983.     int                     switchflag;
  984.  
  985.         argv--;
  986.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  987.                  c == '\n' || c == ';')  ;
  988.         if ( c == '\0' ) {
  989.             warn("Missing date/time after -d");
  990.             return;
  991.         }
  992.  
  993.         while( c != '\0' )  {
  994.         switchflag = false;
  995.         nextdate = (struct Datepairs *) talloc(sizeof(struct Datepairs));
  996.             if ( c == '<' ) {   /*   case: -d <date   */
  997.                 c = *++argv;
  998.                 (nextdate->strtdate)[0] = '\0';
  999.         } elsif (c == '>') {        /*  case:  -d >date     */
  1000.         c = *++argv;
  1001.         (nextdate->enddate)[0] = '\0';
  1002.         switchflag = true;
  1003.         } else {
  1004.                 rawdate = argv;
  1005.         while( c != '<' && c != '>' && c != ';' && c != '\0')
  1006.              c = *++argv;
  1007.                 *argv = '\0';
  1008.         if ( c == '>' ) switchflag=true;
  1009.         if (procdate(switchflag?nextdate->enddate:nextdate->strtdate,
  1010.                  rawdate)==nil) continue;
  1011.         if ( c == ';' || c == '\0') {  /*  case: -d date  */
  1012.             VOID strcpy(nextdate->enddate,nextdate->strtdate);
  1013.             VOID sprintf(nextdate->strtdate,DATEFORM,0,0,0,0,0,0);
  1014.                     nextdate->dnext = duelst;
  1015.                     duelst = nextdate;
  1016.             goto end;
  1017.         } else {
  1018.             /*   case:   -d date<  or -d  date>; see switchflag */
  1019.             while ( (c= *++argv) == ' ' || c=='\t' || c=='\n');
  1020.             if ( c == ';' || c == '\0') {
  1021.             /* second date missing */
  1022.             if (switchflag)
  1023.                 *nextdate->strtdate= '\0';
  1024.             else
  1025.                 *nextdate->enddate= '\0';
  1026.             nextdate->dnext = datelist;
  1027.             datelist = nextdate;
  1028.             goto end;
  1029.             }
  1030.                 }
  1031.             }
  1032.             rawdate = argv;
  1033.         while( c != '>' && c != '<' && c != ';' && c != '\0')
  1034.          c = *++argv;
  1035.             *argv = '\0';
  1036.         if (procdate(switchflag?nextdate->strtdate:nextdate->enddate,
  1037.              rawdate)==nil) continue;
  1038.             nextdate->dnext = datelist;
  1039.         datelist = nextdate;
  1040.      end:
  1041. /*
  1042.         VOID printf("startdate: %s; enddate: %s;\n", nextdate->strtdate,nextdate->enddate);
  1043. */
  1044.         if ( c == '\0')  return;
  1045.             while( (c = *++argv) == ';' || c == ' ' || c == '\t' || c =='\n');
  1046.         }
  1047. }
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053. getnumericrev()
  1054. /*  function:  get the numeric name of revisions which stored in revlist  */
  1055. /*             and then stored the numeric names in Revlst                */
  1056. /*             if branchflag, also add default branch                     */
  1057.  
  1058. {
  1059.         struct  Revpairs        * ptr, *pt;
  1060.         int     flag;
  1061.         char    *temprev;
  1062.  
  1063.         /*  free the previous numeric revision list  */
  1064.         pt = Revlst;
  1065.         while( pt) {
  1066.        ptr = pt->rnext;
  1067.            free((char *)pt);
  1068.            pt = ptr;
  1069.         }
  1070.         Nextdotstring = &Dotstring[0]; /* reset buffer */
  1071.  
  1072.  
  1073.         Revlst = nil;
  1074.         ptr = revlist;
  1075.         while( ptr ) {
  1076.             pt = (struct Revpairs *) talloc(sizeof(struct Revpairs));
  1077.             if ( ptr->numfld == 1 ){ /*  case:  -r rev   */
  1078.                 if ( (flag = expandsym(ptr->strtrev, Nextdotstring)) == true ) {
  1079.                     pt->numfld = countnumflds(Nextdotstring);
  1080.                     pt->strtrev = pt->endrev = Nextdotstring;
  1081.                     while( *Nextdotstring++ != '\0' )  ;
  1082.                 }
  1083.             }
  1084.             else if( ptr->numfld == 2){ /*  case: -r rev-   */
  1085.                 if ( (flag = expandsym(ptr->strtrev, Nextdotstring)) == true) {
  1086.                     pt->numfld = countnumflds(Nextdotstring);
  1087.                     pt->strtrev = Nextdotstring;
  1088.                     while( *Nextdotstring++ != '\0' ) ;
  1089.                     pt->endrev = Nextdotstring;
  1090.                     if ( pt->numfld > 2) choptail(pt->strtrev);
  1091.                     * Nextdotstring++ = '\0';
  1092.                 }
  1093.              }
  1094.              else if(ptr->numfld == 3)  { /*  case: -r -rev   */
  1095.                 if ( (flag = expandsym(ptr->endrev, Nextdotstring)) == true) {
  1096.                     pt->endrev = Nextdotstring;
  1097.                     while( *Nextdotstring++ != '\0' )  ;
  1098.                     pt->numfld = countnumflds(pt->endrev);
  1099.                     pt->strtrev = Nextdotstring;
  1100.                     if ( pt->numfld == 2)
  1101.                         *Nextdotstring++ = '1';
  1102.                     else
  1103.                         choptail(pt->endrev);
  1104.                     *Nextdotstring++ = '.';
  1105.                     *Nextdotstring++ = '1';
  1106.                     *Nextdotstring++ = '\0';
  1107.                 }
  1108.              }
  1109.              else  {     /*   case:  -r rev1-rev2   */
  1110.                 if ( (flag = expandsym(ptr->strtrev, Nextdotstring)) == true ) {
  1111.                     pt->strtrev = Nextdotstring;
  1112.                     while( *Nextdotstring++ != '\0' )  ;
  1113.                     if ( ( flag = expandsym(ptr->endrev, Nextdotstring)) == true)  {
  1114.                         pt->numfld = countnumflds(pt->strtrev);
  1115.                         pt->endrev = Nextdotstring;
  1116.                         while( *Nextdotstring++ != '\0' ) ;
  1117.                         if((flag = checkrevpair(pt->strtrev, pt->endrev)) == true)
  1118.                            /*  switch pt->strtrev with pt->endrev, if pt->strtrev > pt->endre  */
  1119.                             if (compartial(pt->strtrev, pt->endrev, pt->numfld) > 0 ) {
  1120.                                 temprev = pt->strtrev;
  1121.                                 pt->strtrev = pt->endrev;
  1122.                                 pt->endrev = temprev;
  1123.                             }
  1124.                      }
  1125.                 }
  1126.              }
  1127.  
  1128.              if ( flag ){
  1129.                 pt->rnext = Revlst;
  1130.                 Revlst = pt;
  1131.              }
  1132.              else
  1133.                 free((char *)pt);
  1134.              ptr = ptr->rnext;
  1135.         }
  1136.         /* Now take care of branchflag */
  1137.         if (branchflag) {
  1138.             flag =true;
  1139.             pt = (struct Revpairs *) talloc(sizeof(struct Revpairs));
  1140.             if (Dbranch) {
  1141.                 pt->strtrev = pt->endrev = Dbranch->num;
  1142.             } elsif (Head!=nil) {
  1143.                 pt->strtrev = pt->endrev = /* branch number of head */
  1144.                     partialno(Nextdotstring,Head->num,1);
  1145.                 while( *Nextdotstring++ != '\0' ) ;
  1146.             } else flag = false;
  1147.             if (flag) { /* prepend new node */
  1148.                 pt->rnext=Revlst; Revlst=pt;
  1149.                 pt->numfld = countnumflds(pt->strtrev);
  1150.             }
  1151.         }
  1152.  
  1153. }
  1154.  
  1155.  
  1156.  
  1157. checkrevpair(num1,num2)
  1158. char    *num1,  *num2;
  1159. /*  function:  check whether num1, num2 are legal pair,i.e.
  1160.     only the last field are different and have same number of
  1161.     feilds( if length <= 2, may be different if first field)   */
  1162.  
  1163. {
  1164.         int    length;
  1165.  
  1166.         if ( (length = countnumflds(num1)) != countnumflds(num2) ) {
  1167.             error(" Invalid branch or revision pair %s : %s", num1, num2);
  1168.             return false;
  1169.         }
  1170.         if ( length > 2 )
  1171.             if (compartial(num1, num2, length-1) != 0) {
  1172.                 error("Invalid branch or revision pair %s : %s", num1, num2);
  1173.                 return false;
  1174.             }
  1175.  
  1176.         return true;
  1177. }
  1178.  
  1179.  
  1180.  
  1181. getrevpairs(argv)
  1182. register     char    * argv;
  1183. /*  function:  get revision or branch range from command line, and   */
  1184. /*             store in revlist                                      */
  1185.  
  1186. {
  1187.         register    char    c;
  1188.         struct      Revpairs  * nextrevpair;
  1189.         int         flag;
  1190.  
  1191.         argv--;
  1192.         while( ( c = (*++argv)) == ',' || c == ' ' || c == '\t' ||
  1193.                  c == '\n' || c == ';')  ;
  1194.         if ( c == '\0' ) {
  1195.             warn(" Missing revision or branch number after -r");
  1196.             return;
  1197.         }
  1198.  
  1199.         while( c != '\0') {
  1200.             while(  c  == ',' || c == ' ' || c == '\t' ||
  1201.                      c == '\n' || c == ';') c = *++argv;
  1202.             if (c == '\0')  return;
  1203.             nextrevpair = (struct Revpairs *) talloc(sizeof(struct Revpairs));
  1204.             nextrevpair->rnext = revlist;
  1205.             revlist = nextrevpair;
  1206.             nextrevpair->numfld  = nil;
  1207.             nextrevpair->strtrev = nil;
  1208.             nextrevpair->endrev  = nil;
  1209.             flag = false;
  1210.             if (  c == '<' || c == '-' ) {  /*  case: -r -rev  or -r <rev  */
  1211.                 flag = true;
  1212.                 while( (c =(*++argv)) == ' ' || c == '\t' || c =='\n') ;
  1213.             }
  1214.             else {
  1215.                 nextrevpair->strtrev = argv;
  1216.                 /*   get a revision or branch name  */
  1217.                 while( c != ',' && c != ';' && c != ' ' && c != '\0' && c != '-'
  1218.                         && c != '\t' && c != '\n' && c != '<') c = *++argv;
  1219.  
  1220.                 *argv = '\0';
  1221.  
  1222.                 if ( c != '<' && c != '-') {    /*  case: rev  */
  1223.                     nextrevpair->numfld = 1;
  1224.                     continue;
  1225.                 }
  1226.  
  1227.                 if ( (c =(*++argv)) == ',' || c == '\0' || c == ' '
  1228.                       || c == '\t' || c == '\n' || c == ';') {/*  case: rev_  */
  1229.                     nextrevpair->numfld = 2;
  1230.                     continue;
  1231.                 }
  1232.             }
  1233.             nextrevpair->endrev = argv;
  1234.             while( c != ',' && c != ' ' && c != '\0' && c != '\t' && c != '<'
  1235.                    && c != '\n' && c != '-' && c != ';')  c = *++argv;
  1236.  
  1237.             * argv = '\0';
  1238.             if ( c == '<'){
  1239.                 error("separator expected near %s", nextrevpair->endrev);
  1240.                 while( (c = *++argv) != ',' && c != ' ' && c != '\0' &&
  1241.                         c != '\t' && c != '\n' && c != ';' ) ;
  1242.                 revlist = nextrevpair->rnext;
  1243.                 continue;
  1244.             }
  1245.             else  {
  1246.                 if (flag)   /*  case:  -rev   */
  1247.                     nextrevpair->numfld  = 3;
  1248.  
  1249.                 else     /*   rev1-rev2  appears  */
  1250.                     nextrevpair->numfld = 4;
  1251.             }
  1252.         }
  1253. }
  1254.  
  1255.  
  1256.  
  1257. choptail(strhead)
  1258. char     * strhead;
  1259. /*   function : chop off the last field of a branch or a revision number  */
  1260.  
  1261. {
  1262.         char    *pt, *sp;
  1263.  
  1264.         for(pt = Nextdotstring-1; pt != strhead && *pt != '.'; pt--) ;
  1265.         for(sp = strhead; sp < pt; sp++) *Nextdotstring++ = *sp;
  1266. }
  1267.  
  1268.